home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / Developer Essentials Jul 90 / Programming / MPW Dynamo 3.0 / app.builder / build.a < prev    next >
Encoding:
Text File  |  1990-04-02  |  15.2 KB  |  820 lines  |  [TEXT/MPS ]

  1. ****************************************************************
  2. *                            *
  3. * buildapp.system                        *
  4. *                            *
  5. * Apple II 8-bit application builder and launcher.        *
  6. * Copyright (C) 1990 Apple Computer.            *
  7. * Version 3.0                        *
  8. *                            *
  9. * Written by Eric Soldan, Apple II DTS            *
  10. *                            *
  11. ****************************************************************
  12.  
  13.         include    ':dynamo.includes:sys.equ'
  14.         include    ':dynamo.includes:rt.h'
  15.         include    ':dynamo.includes:rt.macros'
  16.  
  17.         include    'app.config'
  18.  
  19. *********************************************
  20.  
  21. buildText    equ    $1600        ;Script file for building application.
  22.  
  23. fileName        equ    $1E00        ;filestr starts at $1E01.  Runtime
  24.                     ;strings aren't pascal-type.  There
  25.                     ;is a table called strlens that holds
  26.                     ;the lengths.  There is another table
  27.                     ;called maxstrlens that defines how
  28.                     ;big each string can get.
  29.                     ;To make a pascal string for ProDOS,
  30.                     ;the characters for the file name
  31.                     ;are placed in filstr.  Then the
  32.                     ;string length byte is copied to
  33.                     ;fileName, just in front of filestr.
  34.                     ;Now we have a regular pascal string
  35.                     ;for ProDOS.
  36. btFileName    equ    $1E80        ;This is the boot time file name.  If
  37.                     ;the user of BUILDAPP.SYSTEM wants to
  38.                     ;have his text in a file other than
  39.                     ;BUILDAPP.TEXT, or if the script file
  40.                     ;is in another directory, then he can
  41.                     ;place the pathname of the file into
  42.                     ;BUILDAPP.SYSTEM, starting at byte $2006.
  43.                     ;This is the standard way for launched
  44.                     ;programs to be given a pathname.  The
  45.                     ;default pathname in this location
  46.                     ;is BUILDAPP.TEXT. btpathstr starts at
  47.                     ;$1E81.  This string works like filestr,
  48.                     ;in reverse.  The pascal string is first
  49.                     ;copied into btFileName, and then the
  50.                     ;length byte is stored in the strlens
  51.                     ;table.  The reason for copying the
  52.                     ;string from $2006 is because this area
  53.                     ;will be written over, and if the user
  54.                     ;wants to re-run the program due to an
  55.                     ;error, this string would have been lost.
  56.  
  57. *********************************************
  58.  
  59. MLI        equ    $BF00        ;Various equates for ProDOS.
  60. paramCount    equ    $00
  61.  
  62. CREATE        equ    $C0
  63. create_pathname    equ    $01
  64. create_access    equ    $03
  65. create_filetype    equ    $04
  66. create_auxtype    equ    $05
  67. create_strgtype    equ    $07
  68. create_createdate    equ    $08
  69. create_createtime    equ    $0A
  70.  
  71. OPEN        equ    $C8
  72. open_pathname    equ    $01
  73. open_iobuffer    equ    $03
  74. open_refnum    equ    $05
  75.  
  76. READ        equ    $CA
  77. read_refnum    equ    $01
  78. read_databuffer    equ    $02
  79. read_reqcount    equ    $04
  80. read_transcount    equ    $06
  81.  
  82. WRITE        equ    $CB
  83. write_refnum    equ    $01
  84. write_databuffer    equ    $02
  85. write_reqcount    equ    $04
  86. write_transcount    equ     $06
  87.  
  88. SETEOF        equ    $D0
  89. setEOF_refnum    equ    $01
  90. setEOF_EOF    equ    $02
  91.  
  92. SETFILEINFO    equ    $C3
  93. setInfo_pathname    equ    $01
  94. setInfo_access    equ    $03
  95. setInfo_filetype    equ    $04
  96. setInfo_auxtype    equ    $05
  97. setInfo_nullfield    equ    $07
  98. setInfo_moddate    equ    $0A
  99. setInfo_modtime    equ    $0C
  100.  
  101. GETFILEINFO    equ    $C4
  102. getInfo_pathname    equ    $01
  103. getInfo_access    equ    $03
  104. getInfo_filetype    equ    $04
  105. getInfo_auxtype    equ    $05
  106. getInfo_strgtype    equ    $07
  107. getInfo_blksused    equ    $08
  108. getInfo_moddate    equ    $0A
  109. getInfo_modtime    equ    $0C
  110. getInfo_crdate    equ    $0E
  111. getInfo_crtime    equ    $10
  112.  
  113. CLOSE        equ    $CC
  114. close_refnum    equ    $01
  115.  
  116. QUIT        equ    $65
  117.  
  118. *********************************************
  119.  
  120. numstrings    equ    5
  121.  
  122. bffrstr        equ    0
  123. maxbffrstr    equ    127
  124. bffrstrloc    equ    $1D01
  125.  
  126. tempstr        equ    1
  127. maxtempstr    equ    127
  128. tempstrloc    equ    $1D81
  129.  
  130. filestr        equ    2
  131. maxfilestr    equ    127
  132. filestrloc    equ    $1E01
  133.  
  134. btpathstr    equ    3
  135. maxbtpathstr    equ    64
  136. btpathstrloc    equ    $1E81
  137.  
  138. pathstr        equ    4
  139. maxpathstr    equ    127
  140. pathstrloc    equ    $2007
  141.  
  142. *********************************************
  143.  
  144.         export    varspace
  145. varspace        PROC
  146.         ds.b    256
  147.         endp
  148.  
  149. ******************
  150.  
  151.         export    strspace
  152. strspace        PROC
  153.         export    strlens, maxstrlens, strlocs
  154. strlens        ds.b    numstrings
  155. maxstrlens    dc.b    maxbffrstr, maxtempstr, maxfilestr, maxbtpathstr, maxpathstr
  156. strlocs        dc.w    bffrstrloc, tempstrloc, filestrloc, btpathstrloc, pathstrloc
  157.         endp
  158.  
  159. ******************
  160.  
  161. main        PROC
  162.  
  163.         lda    #0        ;Clear the variable space.
  164.         tax            ;This application does not
  165. @clearvars    sta    varspace,x    ;need to variables to be
  166.         inx            ;pre-cleared.
  167.         bne    @clearvars
  168.  
  169.         ldx    #64        ;Get boot path from system
  170. @getPath        lda    $2006,x        ;file and place it in btpathstr.
  171.         sta    btFileName,x
  172.         dex
  173.         bpl    @getPath
  174.         lda    btFileName
  175.         sta    strlens+btpathstr
  176.  
  177. ******************
  178.  
  179. restart        lda #0            ;This string is the last read from the
  180.         sta    strlens+bffrstr    ;buildapp.text file.  Init it to NULL.
  181.  
  182.         jsr    $C300        ;Initialize 80-col screen.
  183.         _writecr
  184.         jsr    home
  185.  
  186.         _rtreset
  187.         _hibitchrs
  188.  
  189.         _write    'IIe Application builder  v3.0',13,\
  190.             'Copyright (C) 1990 by Apple Computer.',13,13,\
  191.             'Building application, please wait.',13,13,13
  192.  
  193.         _strcpy    filestr,btpathstr
  194.                     ;Put file name of load build text
  195.                     ;in filestr.  All proDOS operations
  196.                     ;that need a file name expect it in
  197.                     ;filestr in this application.
  198.  
  199.         jsr    loadFile
  200.         dc.w    buildText
  201.         dc.w    $FFFF
  202.         bcc    @a
  203.         _write    13,13,'Could not load '
  204.         _prstr    filestr
  205.         _write    '.'
  206.         jmp    abort
  207.  
  208.  
  209. @a        lda    readBlock+read_transcount
  210.         sta    ptr
  211.         lda    readBlock+read_transcount+1
  212.         clc
  213.         adc    #>buildText    ;Make sure that the build text
  214.         sta    ptr+1        ;ends with a c/r, or else _readstr
  215.         lda    #13        ;may get real unhappy.
  216.         ldy    #0
  217.         sta    (ptr),y
  218.         iny            ;If a string of 1 char (a 255) is read,
  219.         iny            ;then the end of the file was read
  220.         sta    (ptr),y        ;prematurely, and an error will be issued.
  221.         dey
  222.         lda    #255
  223.         sta    (ptr),y
  224.  
  225.  
  226.         _restore #buildText    ;Point readData at buildText.
  227.         _readend #13        ;_readstr will stop at a c/r.
  228.  
  229.         _set    buildaddr,*$2006+65
  230. * The dispatcher has the ending location stored in this address.  Point after
  231. * dispatcher.  We don't have to load the dispatcher, since it is already at
  232. * $2000.  (It was used to launch this application.)
  233.  
  234.         _var    pathstr        ;pathstr location is $2007, so text
  235.         jsr    getstr        ;is read directly into dispatcher.
  236.         bcc    @ok1
  237.         jsr    EOFMessage
  238.         _write    'pathname.'
  239.         jmp    abort
  240.  
  241.  
  242. @ok1        lda    strlens+pathstr
  243.         sta    $2006        ;Make a pascal string out of it.
  244.  
  245. ******************
  246.  
  247. mainloop        _var    mode
  248.         jsr    getint
  249.         bcc    @ok2
  250.         jsr    EOFMessage
  251.         _write    'bank selection bit setting.'
  252.         jmp    abort
  253.  
  254. @ok2        lda    varspace+mode+1
  255.         bne    @bad2
  256.         lda    varspace+mode
  257.         and    #$87
  258.         cmp    varspace+mode
  259.         beq    @ok2a
  260. @bad2        _write    'Bad bank selection bit setting ('
  261.         _var    mode
  262.         lda    decimalint
  263.         bne    @bad2a
  264.         _write    '$'
  265.         _vhexout
  266.         jmp    @bad2b
  267. @bad2a        _vdecout
  268. @bad2b        _write    ').'
  269.         jmp    abort
  270.  
  271. @ok2a        _var    address
  272.         jsr    getint
  273.         bcc    @ok3
  274.         jsr    EOFMessage
  275.         lda    varspace+mode
  276.         bpl    @aa
  277.         _write    'starting'
  278.         jmp    @ab
  279. @aa        _write    'segment'
  280. @ab        _write    ' address.'
  281.         jmp    abort
  282.  
  283. @ok3        lda    varspace+mode    ;Bit 7 of mode byte indicates no
  284.         bpl    @a        ;more segments.  Following field
  285.         jmp    startaddr    ;is launch address.
  286.  
  287. @a        _var    filestr
  288.         jsr    getstr
  289.         bcc    @ok4
  290.         jsr    EOFMessage
  291.         _write    'filename.'
  292.         jmp    abort
  293.  
  294. @ok4        _write 'Loading '
  295.         _prstr filestr
  296.         _write '...',13
  297.  
  298.         lda    varspace+buildaddr ;Make space for 5 bytes that
  299.         clc            ;will be filled in later.
  300.         adc    #5
  301.         sta    @addr
  302.         lda    varspace+buildaddr+1
  303.         adc    #0
  304.         sta    @addr+1
  305.         jsr    loadFile
  306. @addr        dc.w    $2000
  307.         dc.w    $FFFF
  308.         bcc    @b
  309.         jmp    noLoad
  310.  
  311. @b        lda    varspace+buildaddr ;Put the segment relocation
  312.         sta    ptr        ;information in front of segment.
  313.         lda    varspace+buildaddr+1
  314.         sta    ptr+1
  315.         ldy    #0
  316.         lda    varspace+mode
  317.         sta    (ptr),y
  318.         iny
  319.         lda    varspace+address
  320.         sta    (ptr),y
  321.         iny
  322.         lda    varspace+address+1
  323.         sta    (ptr),y
  324.         iny
  325.         lda    readBlock+read_transcount
  326.         sta    (ptr),y
  327.         iny
  328.         lda    readBlock+read_transcount+1
  329.         sta    (ptr),y
  330.  
  331.         lda    ptr        ;Point past segment.
  332.         clc
  333.         adc    #5
  334.         bcc    @c
  335.         inc    ptr+1
  336.         clc
  337. @c        adc    readBlock+read_transcount
  338.         sta    varspace+buildaddr
  339.         lda    ptr+1
  340.         adc    readBlock+read_transcount+1
  341.         sta    varspace+buildaddr+1
  342.  
  343.         jmp    mainloop        ;Load another segment.
  344.  
  345. startaddr    _write    13,'Starting address is '
  346.         _var    tempstr
  347.         jsr    getstr
  348.         bcc    @ok5
  349.         jsr    crEOFMessage
  350.         _write    'address display format.'
  351.         jmp    abort
  352.  
  353. @ok5        lda    tempstrloc
  354.         _var    address
  355.         cmp    #'$'
  356.         beq    @hex
  357.         _vdecout
  358.         jmp    @a
  359. @hex        _rtcout
  360.         _vhexout
  361. @a        _writecr
  362.  
  363.         lda    varspace+buildaddr ;Store the launch information.
  364.         sta    ptr
  365.         lda    varspace+buildaddr+1
  366.         sta    ptr+1
  367.         ldy    #0
  368.         lda    varspace+mode
  369.         sta    (ptr),y
  370.         iny
  371.         lda    varspace+address
  372.         sta    (ptr),y
  373.         iny
  374.         lda    varspace+address+1
  375.         sta    (ptr),y
  376.  
  377.         lda    ptr        ;Calculate application size.
  378.         sec
  379.         sbc    #<$2000-3
  380.         sta    varspace+applen
  381.         lda    ptr+1
  382.         sbc    #>$2000-3
  383.         sta    varspace+applen+1
  384.  
  385.         _write    13,'Application length is '
  386.         _var    tempstr
  387.         jsr    getstr
  388.         bcc    @ok6
  389.         jsr    crEOFMessage
  390.         _write    'length display format.'
  391.         jmp    abort
  392.  
  393. @ok6        lda    tempstrloc
  394.         _var    applen
  395.         cmp    #'$'
  396.         beq @hex0
  397.         _vdecout
  398.         jmp @a0
  399. @hex0        _rtcout
  400.         _vhexout
  401.  
  402. @a0        _write    13,13,'Save application? (Y,N,Q) '
  403.         _var    tempstr        ;See if we have a script value for
  404.         jsr    getstr        ;Y,N,Q.
  405.         ldx    strlens+tempstr
  406.         beq    @b        ;Nothing, so no Y,N,Q script command.
  407.         lda    tempstrloc
  408.         and    #$5F
  409.         cmp    #'Y'
  410.         beq    @b0
  411.         cmp    #'N'
  412.         beq    @b0
  413.         cmp    #'Q'
  414.         beq    @b0        ;Wasn't a Y,N,Q script command.
  415. @b        jsr    rdkey
  416. @b0        and    #$5F
  417.         cmp    #'Y'
  418.         beq    saveit
  419.         cmp    #'N'
  420.         beq    runit
  421.         cmp    #'Q'
  422.         bne    @b
  423.  
  424. quit        jsr    rtcout
  425.         jsr    MLI
  426.         dc.b    QUIT
  427.         dc.w    @parmTable
  428. @parmTable    dc.b    4
  429.         dc.b    0
  430.         dc.w    0
  431.         dc.b    0
  432.         dc.w    0
  433.  
  434. runit        jsr    rtcout
  435.         jmp    $2000
  436.  
  437. saveit        jsr    rtcout
  438.         _var    filetype
  439.         jsr    getint
  440.         bcc    @ok7
  441.         jsr    crEOFMessage
  442.         _write    'filetype.'
  443.         jmp    abort
  444.  
  445. @ok7        _var    auxtype
  446.         jsr    getint
  447.         bcc    @ok8
  448.         jsr    crEOFMessage
  449.         _write    'auxtype.'
  450.         jmp    abort
  451.  
  452. @ok8        _writecr            ;Go ahead and save it.
  453.         _var    filestr
  454.         jsr    getstr
  455.         bcc    @ok9
  456.         jsr    crEOFMessage
  457.         _write    'application filename.'
  458.         jmp    abort
  459.  
  460. @ok9        _write    13,'Saving application as '
  461.         _prstr
  462.         lda    varspace+applen
  463.         sta    @len
  464.         lda    varspace+applen+1
  465.         sta    @len+1
  466.         jsr    saveFile
  467.         dc.w    $2000
  468. @len        dc.w    $FFFF
  469.         bcc @a
  470.         _write    13,13,'Could not save '
  471.         _prstr    filestr
  472.         _write    '.'
  473.         jmp    abort
  474.  
  475. @a        jsr    getFileInfo    ;Update filetype and auxtype.
  476.         bcc    @b
  477.         _write    13,13,'Could not get file info for '
  478.         _prstr    filestr
  479.         _write    '.'
  480.         jmp    abort
  481.  
  482. @b        jsr    getToSet        ;Move getInfo data to setInfo block.
  483.         lda    varspace+filetype    ;Set filetype and auxtype.
  484.         sta    setFileInfoBlock+setInfo_filetype
  485.         lda    varspace+auxtype
  486.         sta    setFileInfoBlock+setInfo_auxtype
  487.         jsr    setFileInfo
  488.         bcc    @c
  489.         _write    13,13,'Could not set file info for '
  490.         _prstr    filestr
  491.         _write    '.'
  492.         jmp    abort
  493.  
  494. @c        jmp    $2000        ;Launch application.
  495.  
  496.  
  497. noLoad        _write    13,13,'Could not load '
  498.         _prstr    filestr
  499.         _write    '.'
  500.  
  501. abort        _write    13,'Please fix and press any key to rebuild ',\
  502.             '(or Q to quit). '
  503.         jsr    rdkey
  504.         and    #$5F
  505.         cmp    #'Q'
  506.         bne    @a
  507.         jmp    quit
  508. @a        jmp    restart
  509.  
  510.  
  511. getstr        txa
  512.         pha
  513.         jsr    fillbffrstr
  514.         pla
  515.         tax
  516.         bcs    @rts
  517. @ok        _strcpy    ,bffrstr
  518.         lda    #0
  519.         sta    strlens+bffrstr
  520.         clc
  521. @rts        rts
  522.  
  523.  
  524. getint        stx    @xreg
  525.         jsr    fillbffrstr    ;Make sure we have something to chew.
  526.         bcs    @exit        ;If we don't, return an error.
  527.         _strval    bffrstr        ;Get the value of the string and
  528.         ldx    @xreg        ;put it in the variable.
  529.         _set
  530.         _var    bffrstr
  531.         ldy    #0
  532.         sty    decimalint
  533. @a        tya            ;First skip over -'s.
  534.         _strchr
  535.         iny
  536.         cmp    #'-'
  537.         beq    @a
  538.         cmp    #'$'
  539.         beq    @b
  540.         dec    decimalint    ;It was a decimal integer.
  541. @b        ldy    strvalcount
  542. @c        tya
  543.         cmp    strlens,x
  544.         bcs    @d        ;Ran out of string.
  545.         _strchr
  546.         iny
  547.         cmp    #','
  548.         bne    @c
  549.         tya
  550. @d        _midstrcpy ,bffrstr
  551.         clc            ;All went well.
  552. @exit        ldx    @xreg        ;Restore x-reg.
  553.         rts            ;All done
  554. @xreg        dc.b    0
  555. decimalint    dc.b    0
  556.  
  557.  
  558. fillbffrstr    lda    strlens+bffrstr    ;See if there is any string left.
  559.         beq    @a        ;There is not, so get another.
  560.         clc
  561.         rts            ;There is, so munch away.
  562. @a        _readstr    bffrstr        ;Read in the next.
  563.         jsr    stripComment    ;Chew off comments -- (who needs them?)
  564.         lda    strlens+bffrstr    ;How did we do?
  565.         beq    @a        ;Empty line -- try again.
  566.         lda    bffrstrloc    ;Check for eof marker.
  567.         cmp    #255
  568.         rts            ;Return carry set if eof hit.
  569.  
  570.  
  571. stripComment    txa
  572.         asl    a
  573.         tax
  574.         lda    strlocs,x    ;Point to the string.
  575.         sta    ptr
  576.         lda    strlocs+1,x
  577.         sta    ptr+1
  578.         txa
  579.         lsr    a
  580.         tax
  581.         ldy    #0
  582. @a        tya
  583.         cmp    strlens,x
  584.         beq    @b        ;Hit end-of-string.
  585.         lda    (ptr),y
  586.         iny
  587.         cmp    #';'
  588.         bne    @a        ;Not at comment yet.
  589.         dey
  590.  
  591. @b        dey            ;Remove all trailing white-space.
  592.         bpl    @c        ;Still some characters left.
  593.         lda    #0
  594.         sta    strlens,x    ;Ran out of string.
  595.         rts
  596.  
  597. @c        lda    (ptr),y        ;See if it white-space.
  598.         cmp    #9
  599.         beq    @b        ;If it is, keep backing up.
  600.         cmp    #' '
  601.         beq    @b
  602.         iny            ;We ran into something solid.
  603.         tya
  604.         sta    strlens,x
  605.  
  606. @noComment    rts
  607.  
  608. crEOFMessage    _writecr
  609. EOFMessage    _write 'Build script EOF hit while reading '
  610.         rts
  611.  
  612. *********************************************
  613.  
  614.  
  615. createFile    jsr    MLI
  616.         dc.b    CREATE
  617.         dc.w    createBlock
  618.         rts
  619. createBlock    dc.b    7
  620.         dc.w    fileName
  621.         dc.b    $C3
  622.         dc.b    $06
  623.         dc.w    $2000
  624.         dc.b    $01
  625.         dc.w    $00
  626.         dc.w    $00
  627.  
  628.  
  629. setFileInfo    jsr    MLI
  630.         dc.b    SETFILEINFO
  631.         dc.w    setFileInfoBlock
  632.         rts
  633. setFileInfoBlock    dc.b    7
  634.         dc.w    fileName
  635.         dc.b    0
  636.         dc.b    0
  637.         dc.w    0
  638.         ds.b     3
  639.         dc.w    0
  640.         dc.w    0
  641.  
  642.  
  643. getFileInfo    jsr    MLI
  644.         dc.b    GETFILEINFO
  645.         dc.w    getFileInfoBlock
  646.         rts
  647. getFileInfoBlock    dc.b    10
  648.         dc.w    fileName
  649.         dc.b    0
  650.         dc.b    0
  651.         dc.w    0
  652.         ds.b    1
  653.         dc.w    1
  654.         dc.w    0
  655.         dc.w    0
  656.         dc.w    0
  657.         dc.w    0
  658.  
  659.  
  660. getToSet        ldy    #13-1
  661. @a        lda    getFileInfoBlock+getInfo_pathname,y
  662.         sta    setFileInfoBlock+getInfo_pathname,y
  663.         dey
  664.         bpl    @a
  665.         rts
  666.  
  667.  
  668. openFile        jsr    MLI
  669.         dc.b    OPEN
  670.         dc.w    openBlock
  671.         ldx    openBlock+open_refnum
  672.         stx    readBlock+read_refnum
  673.         stx    writeBlock+write_refnum
  674.         stx    setEOFBlock+setEOF_refnum
  675.         stx    closeBlock+close_refnum
  676.         rts
  677. openBlock    dc.b    3
  678.         dc.w    fileName
  679.         dc.w    $BF00-1024
  680.         dc.b    1
  681.  
  682.  
  683. readFile        jsr    MLI
  684.         dc.b    READ
  685.         dc.w    readBlock
  686.         rts
  687. readBlock    dc.b    4
  688.         dc.b    1
  689.         dc.w    $2000
  690.         dc.w    $2000
  691.         dc.w    0
  692.  
  693.  
  694. writeFile    jsr    MLI
  695.         dc.b    WRITE
  696.         dc.w    writeBlock
  697.         rts
  698. writeBlock    dc.b    4
  699.         dc.b    1
  700.         dc.w    $2000
  701.         dc.w    $2000
  702.         dc.w    0
  703.  
  704.  
  705. setEOF        jsr    MLI
  706.         dc.b    SETEOF
  707.         dc.w    setEOFBlock
  708.         rts
  709. setEOFBlock    dc.b    2
  710.         dc.b    1
  711.         ds.b    3
  712.  
  713.  
  714. closeFile    jsr    MLI
  715.         dc.b    CLOSE
  716.         dc.w    closeBlock
  717.         rts
  718. closeBlock    dc.b    1
  719.         dc.b    1
  720.  
  721.  
  722. loadFile        pla            ;Set ptr to point to params.
  723.         sta    ptr
  724.         pla
  725.         sta    ptr+1
  726.         jsr    prepFile        ;Get all data ready.
  727.         lda    ptr+1        ;Restore return address.
  728.         pha
  729.         lda    ptr
  730.         pha
  731.         jsr    openFile        ;Try opening the file.
  732.         bcs    @rts        ;Bad news...
  733.         jsr    readFile        ;Try reading the file.
  734.         bcc    @a        ;Good news.
  735.         php            ;Read failed -- try closing the
  736.         pha            ;file and restoring the error
  737.         jsr    closeFile    ;to the read error status.
  738.         pla
  739.         plp
  740.         rts
  741. @a        jsr    closeFile    ;Return result of close.
  742. @rts        rts
  743.  
  744.  
  745. saveFile        pla            ;Set ptr to point to params.
  746.         sta    ptr
  747.         pla
  748.         sta    ptr+1
  749.         jsr    prepFile        ;Get all data ready.
  750.         lda    ptr+1        ;Restore return address.
  751.         pha
  752.         lda    ptr
  753.         pha
  754.         jsr    createFile    ;Try creating file.
  755.         bcc    @a        ;There was no such file.
  756.         cmp    #$47        ;Make sure error is duplicate file error.
  757.         sec
  758.         bne    @rts
  759.  
  760. @a        jsr    openFile        ;Try opening the file.
  761.         bcs    @rts        ;Bad news...
  762.  
  763.         jsr    writeFile    ;Try writing the file.
  764.         bcc    @b        ;Good news.
  765.         php            ;Write failed -- try closing the
  766.         pha            ;file and restoring the error
  767.         jsr    closeFile    ;to the write error status.
  768.         pla
  769.         plp
  770.         rts
  771.  
  772. @b        lda    writeBlock+write_reqcount
  773.         sta    setEOFBlock+setEOF_EOF
  774.         lda    writeBlock+write_reqcount+1
  775.         sta    setEOFBlock+setEOF_EOF+1
  776.         lda    #0
  777.         sta    setEOFBlock+setEOF_EOF+2
  778.         jsr    setEOF
  779.         bcc    @c
  780.         php
  781.         pha
  782.         jsr    closeFile
  783.         pla
  784.         plp
  785.         rts
  786.  
  787. @c        jsr    closeFile    ;Return result of close.
  788. @rts        rts
  789.  
  790.  
  791. prepFile        lda    strlens+filestr
  792.         sta    fileName        ;Length of string.
  793.         ldy    #1
  794.         lda    (ptr),y
  795.         sta    readBlock+read_databuffer
  796.         sta    writeBlock+write_databuffer
  797.         iny
  798.         lda    (ptr),y
  799.         sta    readBlock+read_databuffer+1
  800.         sta    writeBlock+write_databuffer+1
  801.         iny
  802.         lda    (ptr),y
  803.         sta    readBlock+read_reqcount
  804.         sta    writeBlock+write_reqcount
  805.         iny
  806.         lda    (ptr),y
  807.         sta    readBlock+read_reqcount+1
  808.         sta    writeBlock+write_reqcount+1
  809.         tya
  810.         clc
  811.         adc    ptr
  812.         sta    ptr
  813.         bcc    @d
  814.         inc    ptr+1
  815. @d        rts
  816.  
  817.         endp
  818.  
  819.         END
  820.